//
//  IndexCollectionView.m
//  YunFu
//
//  Created by Bager on 2018/8/30.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "IndexCollectionView.h"

#import "IndexFiveItemSizeCell.h"
#import "SAIndexTabBarVC.h"
#import "BAIndexVC.h"

@implementation IndexCollectionView

- (instancetype)init
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2) / 5.0, (kScreenWidth - kPublicMargin * 2) / 5.0 + 20);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 0;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(0, kPublicMargin, 0, kPublicMargin);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, ((kScreenWidth - kPublicMargin * 2) / 5.0 + 20) * 2)  collectionViewLayout:flowLayout];
    
    self.backgroundColor = [UIColor whiteColor];
    
    if (self)
    {
        self.dataSource = self;
        
        self.delegate = self;
        
        [self registerClass:[IndexFiveItemSizeCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    }
    
    return self;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    IndexFiveItemSizeCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    
    NSArray *imgArray = @[@"yf1-topnav1",@"yf1-topnav6",@"yf1-topnav3",@"yf1-topnav4",@"yf1-topnav5",@"yf1-topnav2",@"yf1-topnav7",@"yf1-topnav8",@"yf1-topnav9",@"yf1-topnav10"];
    [cell.img setImage:[UIImage imageNamed:imgArray[indexPath.item]]];
    NSArray *titleArray = @[@"在线商城", @"名店导航", @"便民服务", @"缴费售票", @"人才信息", @"诚信企业", @"公益服务", @"智慧城市", @"供应链服务", @"在线金融"];
    cell.name.text = titleArray[indexPath.item];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item == 0)
    {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        SAIndexTabBarVC *sa = [SAIndexTabBarVC new];
        window.rootViewController = sa;
    }
    else if (indexPath.item == 1)
    {
        UINavigationController *nav = [Tools sh_viewControllerWith:self].navigationController;
        BAIndexVC *ba = [BAIndexVC new];
        ba.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:ba animated:YES];
    }
    else
    {

    }
}

@end
